package com.shujia.io_.three;

import org.junit.Test;

import java.io.FileWriter;
import java.io.IOException;

public class WriterDemo {


    @Test
    public void test3() throws IOException {
        /*
        void write(String str)
        写入字符串。
        void write(String str, int off, int len)
        写入字符串的某一部分。
         */
        try (FileWriter fw = new FileWriter("file\\e.txt", true)) {
            String str = "明明半年多前从寺院里还俗出来时";
            fw.write(str);
//            fw.write("，身上有足足四十两的巨款");
            fw.write("，身上有足足四十两的巨款", 0, 8);
            fw.flush();
        }

    }

    @Test
    public void test2() throws IOException {
        try (FileWriter fw = new FileWriter("file\\e.txt")) {
            char[] chs = "明明半年多前从寺院里还俗出来时".toCharArray();
            fw.write(chs, 0, chs.length);

            fw.flush();
        }

    }

    @Test
    public void test1() throws IOException {
        FileWriter fw = new FileWriter("file\\d.txt");

        fw.write(97);
        fw.write(37650);

        fw.flush();
        fw.close();
    }
}
